<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>明细</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/dataTables.bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/global.css" media="all"/>

    <style>
        /*#dt-table_wrapper thead{position: absolute;Z-index:888;}
        #dt-table_wrapper tbody{margin-top:-40px !important;}*/
        .form-filter-wrap .form-inline .layui-form-label {
            width: 160px;
        }
    </style>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 page-container">
    <header class="form-filter-wrap">
        <form class="layui-form form-inline" onsubmit="return false">
            <div class="form-group">
                <div class="form-filter">
                    <div style="margin: 5px 0">

                        <div class="form-inner">
                            <label class="layui-form-label">巡察年度：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="startPatrolTime">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-inner">
                            <label class="layui-form-label">问题类别：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="questionType">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-inner">
                            <label class="layui-form-label">单位：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="branch" lay-search>
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-inner">
                            <label class="layui-form-label">督察人员：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="oversee">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div style="margin: 5px 0">

                        <div class="form-inner">
                            <label class="layui-form-label">整改进度：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="questionStatus">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <button style="margin-left: 50px" id="searchBt" class="layui-btn layui-btn-sm"><i
                                class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button type="button" class="layui-btn layui-btn-sm" id="trackRecord"><i class="layui-icon"></i>整改跟踪
                        </button>
                        <button type="button" class="layui-btn layui-btn-sm" id="test4"><i class="layui-icon"></i>查看附件
                        </button>
                        <button class="layui-btn layui-btn-sm" onclick="excel()">
                            <i class="layui-icon"></i> 导出Excel
                        </button>
                    </div>

                </div>
                <!--<div class="form-btn" style="margin-top: 50px">
                    <button type="button" class="layui-btn layui-btn-sm" id="trackRecord"><i class="layui-icon"></i>跟踪记录
                    </button>
                    <button type="button" class="layui-btn layui-btn-sm" id="test4"><i class="layui-icon"></i>查看附件
                    </button>
                    <button class="layui-btn layui-btn-sm" onclick="excel()">
                        <i class="layui-icon"></i> 导出Excel
                    </button>
                </div>-->
            </div>

        </form>
    </header>

    <div class="content-container" style="top: 90px">
        <div class="widget-body no-padding">
            <!---->

            <table id="dt-table"
                   class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th rowspan="2"><input type='checkbox' id='checkAll'/></th>

                    <th rowspan="2">巡察年度</th>
                    <th rowspan="2">督察人员</th>
                    <th rowspan="2">问题类别</th>
                    <th rowspan="2">问题项</th>
                    <th rowspan="2">问题来源</th>
                    <th rowspan="2">问题描述</th>
                    <th colspan="3">巡察回访</th>

                </tr>
                <tr>
                    <th>整改进度</th>
                    <th>整改落实情况</th>
                    <th style="border-right-width: 1px">回访时间</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>

        </div>
    </div>
</div>
<!--附件下载-->
<div id="hidden1" lay-filter="hidden1" style="display: none">
    <table id="department_result" lay-filter="department_result"></table>
</div>

<script type="text/html" id="hidden1-table-tool">
    <a class="layui-btn layui-btn-xs" lay-event="select">选择</a>
</script>


<div id="openProductBox" style="display: none; padding: 10px;">
    <table id="openProductTable" lay-filter="openProductTable"></table>
</div>
<div id="openProductBox2" style="display: none; padding: 10px;">
    <button type="button" lay-event="del" class="layui-btn layui-btn-sm" id="down"><i class="layui-icon"></i>查看附件详情</button>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>


<script type="text/html" id="itemTpl">
    {{# if( d.type == 2 && d.delated == 0){ }}
    <button type="button" lay-event="del1" class="layui-btn layui-btn-sm" id="del1"><i class="layui-icon"></i>删除
    </button>
    {{# } }}

    {{# if( d.type == 3 && d.delated == 1){ }}
    <button type="button" lay-event="del2" class="layui-btn layui-btn-sm" id="del2"><i class="layui-icon"></i>删除
    </button>
    {{# } }}
</script>





<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript" src="../../js/plugin/jquery-download.js"></script>

<script type="text/javascript">
    layui.use('layer', function () {
        var layer = layui.layer;
    });
    var userId = $('.header-demo .layui-nav .layui-nav-item a span#userId', parent.document).text();
    /*公司*/
    layui.use(['layer', 'form', 'jquery'], function () {
        var form = layui.form;
        $.when(
            $.ajax({
                url: '/dropDown/getBranch',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    // 使用循环遍历，给下拉列表赋值
                    $.each(data, function (index, value) {
                        $('#branch').append(new Option(value.value, value.key));// 下拉菜单里添加元素
                    });
                    form.render();//重新渲染 固定写法
                }
            })
            /*年度*/
            , $.ajax({
                url: '/dropDown/getYear',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    // 使用循环遍历，给下拉列表赋值
                    $.each(data, function (index, value) {
                        $('#startPatrolTime').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                    });
                    form.render();//重新渲染 固定写法
                }
            })
            /*整改进度*/
            , $.ajax({
                url: '/dropDown/getSchedule',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    // 使用循环遍历，给下拉列表赋值
                    $.each(data, function (index, value) {
                        $('#questionStatus').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                    });
                    form.render();//重新渲染 固定写法
                }
            })/*督察人员*/
            , $.ajax({
                url: '/dropDown/getOversee',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    // 使用循环遍历，给下拉列表赋值
                    $.each(data, function (index, value) {
                        $('#oversee').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                    });
                    form.render();//重新渲染 固定写法
                }
            })
            ,
            /*问题类别*/
            $.ajax({
                url: '/dropDown/getQuestion',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    // 使用循环遍历，给下拉列表赋值
                    $.each(data, function (index, value) {
                        $('#questionType').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                    });
                    form.render();//重新渲染 固定写法
                }
            })
        ).done(function () {
            setFormValue()
        })


    });

    var pers = checkPermission();

    var foo = function (element) {
        var intent = document.querySelector(element)
        intent.disabled = 'disabled'
        setTimeout(function () {
            intent.disabled = ''
        }, 3000) /* 可以把 3000 改成自定义的时间*/
        console.log('1 秒内不可以重复点击')
    }


    var bar = function (fun, select) {
        var intent = document.querySelector('#test')
        intent.addEventListener('click', function () {
            fun(select)
        })
    }

    bar(foo, "#down")

    $("#test4").click(function () {
        $('th').css({'font-weight': 'bold'})
        layui.use(['table', 'form'], function () {

            var table = layui.table;

            var ids = [];
            $.each($('input[name=\'childclick\']:checkbox'), function () {
                if (this.checked) {
                    ids.push($(this).val())
                }
            });
            var form = layui.form;
            if (ids.length > 1 || ids.length === 0) {
                layer.msg('请选择一条数据查看');

            } else {
                var id = ids[0]
                $.ajax({
                    url: '/mOverseeQuestions/fileList',
                    dataType: 'json',
                    type: 'post',
                    data: {id: id},
                    success: function (data) {

                        if (data.count === 0) {
                            layer.msg('未上传附件');
                        } else {
                            layer.open({
                                type: 1,
                                title: '<div class="layui-icon" style="font-weight: bold;text-align: center"> 附件列表</div>',
                                area: ['80%', '80%'], //宽高
                                content: $('#openProductBox2'),
                                success: function (data) {
                                    table.render({
                                        elem: '#test',
                                        width: '100%'
                                        , method: 'post', //接口http请求类型，默认：get
                                        page: false,
                                        limit: Number.MAX_VALUE,
                                        url: '/mOverseeQuestions/fileList', //?page=1&limit=10（该参数可通过 request 自定义）
                                        where: {id: id},
                                        cols: [[
                                            {
                                                type: 'checkbox'
                                            }, {
                                                field: 'branch', //字段名
                                                title: '单位名称', //标题
                                                width: 200
                                                //fixed: 'left' //固定列
                                            }, {
                                                field: 'question', //字段名
                                                title: '问题项', //标题
                                                width: 260
                                            }, {
                                                field: 'path', //字段名
                                                title: '附件名称', //标题
                                                width: 454
                                            }, {
                                                field: '', title: '操作',
                                                width: 80,
                                                toolbar: '#itemTpl',
                                                fixed: 'right' //固定列
                                            }
                                        ]
                                        ],
                                        done: function (res, curr, count) {
                                            $('th').css({'font-weight': 'bold'});
                                        }
                                    });
                                }
                            });
                        }
                    }
                })

            }
        });
        layui.use('table', function () {
            var table = layui.table;


            //监听行工具事件
            table.on('tool(test)', function (obj) {
                //var checkStatus = layui.table.checkStatus('openProductBox2').data;
                var data = obj.data;

                if (obj.event === 'del1') {
                    var id = data.id;
                    $.ajax({
                        url: '/mOverseeQuestions/deletePathOne?id=' + id,
                        type: 'get',
                        success: function () {
                            layer.msg("删除申请已发出", {
                                icon: 1,
                                time: 1000
                            });
                            table.reload("test");
                        }
                    })
                }
                if (obj.event === 'del2') {
                    var id = data.id;
                    $.ajax({
                        url: '/mOverseeQuestions/deletePathTwo?id=' + id,
                        type: 'get',
                        success: function () {
                            layer.msg("删除成功", {
                                icon: 1,
                                time: 1000
                            });
                            table.reload("test");
                        }
                    })
                }
            });
        });


    })

    function sleep(n) {
        var start = new Date().getTime();//定义起bai始时间的毫秒数
        while (true) {
            var time = new Date().getTime();//每次执行循环取得du一次当前时间的毫秒数
            if (time - start > n) {//如果当前时间的毫秒数减去起始时间的毫秒数大于给定的毫秒数，即结束循环
                break;
            }
        }
    }

    // 附件下载
    function aa() {
        var checkStatus = layui.table.checkStatus('test').data;
        var ids = [];
        for (var i = 0; i < checkStatus.length; i++) {
            ids.push(checkStatus[i].id)
        }
        if (ids.length === 0) {
            layer.msg('请选择数据查看');
            return
        }

        var url = "/mOverseeQuestions/downSource?id=" + encodeURI(JSON.stringify(ids));
        $.fileDownload(url, {
            httpMethod: 'GET',
            //同时上传表单数据
            data: '',
            prepareCallback: function (url) {
                $('#down').attr('disabled', false)
                console.log("请稍等！");
            },
            successCallback: function (url) {

                $('#down').attr('disabled', false)
                return false
            },
            failCallback: function (html, url) {
                var json = JSON.parse(html);
                console.log(json);
                $('#down').attr('disabled', false)
            }
        });
        return false
    }

    $('#down').on('click', function () {
        aa()
    })


    $("#trackRecord").click(function () {

        layui.use(['table', 'form'], function () {

            /*  var table2 = layui.table;

              var id = $('input[type="radio"]:checked').val()

              console.log($('input[type="radio"]:checked').val())*/

            var table2 = layui.table;
            var ids = [];
            $.each($('input[name=\'childclick\']:checkbox'), function () {
                if (this.checked) {
                    ids.push($(this).val())
                }
            });

            var form = layui.form;
            if (ids.length > 1 || ids.length === 0) {
                layer.msg('请选择一条数据查看');

            } else {
                var id = ids[0];
                $.ajax({
                    url: '/questionRecords/' + id,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        if (data.code === 1) {
                            layer.msg('暂无记录');
                        } else {
                            layer.open({
                                type: 1,
                                title: '<div class="layui-icon" style="font-weight: bold;text-align: center">跟踪记录</div>',
                                area: ['80%', '80%'], //宽高
                                content: $('#openProductBox'),
                                success: function () {
                                    table2.render({
                                        elem: '#openProductTable',
                                        id: 'openProductTable',
                                        height: 480,
                                        method: 'get', //接口http请求类型，默认：get
                                        url: '/questionRecords/' + id, //?page=1&limit=10（该参数可通过 request 自定义）
                                        cols: [
                                            [{
                                                field: 'questionStatus', //字段名
                                                title: '整改进度', //标题
                                                width: 100
                                                //fixed: 'left' //固定列
                                            }, {
                                                field: 'updateUser', //字段名
                                                title: '督察人员', //标题
                                                width: 100
                                                //fixed: 'left' //固定列
                                            }, {
                                                field: 'createTime', //字段名
                                                title: '跟踪时间', //标题
                                                templet: '<div>{{layui.util.toDateString(d.supplyStatrTime, "yyyy-MM-dd")}}</div>',
                                                sort: true,
                                                width: 200
                                                //fixed: 'left' //固定列
                                            }, {
                                                field: 'detail', //字段名
                                                title: '整改落实情况' //标题
                                                ,templet: function (data){

                                                        if (data.detail.length > 50) {
                                                            return data.detail.substr(0, 50) + " <a style='color: #1E9FFF ;font-size: 8px' href='javascript:void(0);' onclick='javascript:searchBtn3(\"" + data.detail + "\", \"" + '整改落实详情' + "\")' ><i style='font-weight: bold' class='layui-icon layui-icon-search'></i></a> ";
                                                        } else {
                                                            return data.detail;
                                                        }

                                                }


                                                //fixed: 'left' //固定列
                                            }]
                                        ],
                                        done: function (res, curr, count) {

                                            $('th').css({'font-weight': 'bold'});
                                        }
                                    });
                                }
                            });
                        }
                    }
                })
            }
        });
    })

    function tdTitle(){
        $('th').each(function(index,element){
            $(element).attr('title',$(element).text());
        });
        $('td').each(function(index,element){
            $(element).attr('title',$(element).text());
        });
    };


    var example;

    function init() {
        example =
            $('#dt-table').DataTable({
                data: '',
                retrieve: true,
                "searching": false,
                "processing": false,
                "serverSide": true,
                "ordering": false,
                'iDisplayLength': 8,
                "language": {
                    "url": "/js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url": "/mOverseeQuestions/detailList",
                    "type": "get",
                    "data": function (d) {

                        if ($("#questionType").val() != null) {
                            d.questionType = JSON.stringify($("#questionType").val());
                        }
                        if ($("#startPatrolTime").val() != null) {
                            d.startPatrolTime = JSON.stringify($("#startPatrolTime").val());
                        }
                        if ($("#branch").val() != null) {
                            d.branchId = JSON.stringify($("#branch").val());
                        }
                        if ($("#questionStatus").val() != null) {
                            d.questionStatus = JSON.stringify($("#questionStatus").val());
                        }
                        if ($("#oversee").val() != null) {
                            d.oversee = JSON.stringify($("#oversee").val());
                        }
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'table-bottom col-sm-10 col-xs-12 hidden-xs'i><'table-bottom col-xs-12 col-sm-10' p v>>",
                "bAutoWidth": false,
                "autoWidth": false,
                "scrollCollapse": false,

                "columns": [
                    {
                        "data": "id",
                        "render": function (data, type, row, meta) {
                            return "<input type='checkbox' class='table-checkbox' onclick='childclick(" + data + ")' name='childclick' id='' value=" + data + " />";
                        }
                    },

                    {"width": "90", "data": "startPatrolTime", "defaultContent": "",},
                    {"width": "100", "data": "oversee", "defaultContent": "",},
                    {"width": "100", "data": "questionType", "defaultContent": "",},
                    {
                        "width": "200",
                        "data": "question", "defaultContent": "",
                        render: function (data, type, row, meta) {
                            if (data) {
                                if (data.length > 50) {
                                    return data.substr(0, 50) + " <a style='color: #1E9FFF ;font-size: 8px' href='javascript:void(0);' onclick='javascript:searchBtn3(\"" + data + "\", \"" + '问题项' + "\")' ><i style='font-weight: bold' class='layui-icon layui-icon-search'></i></a> ";
                                } else {
                                    return data;
                                }
                            } else {
                                return "";
                            }
                        }
                    },
                    {"width": "100", "data": "sourceProblem", "defaultContent": "",},
                    {
                        "width": "",
                        "data": "questionDetail", "defaultContent": "",
                        render: function (data, type, row, meta) {
                            if (data) {
                                if (data.length > 50) {
                                    return data.substr(0, 50) + " <a style='color: #1E9FFF ;font-size: 8px' href='javascript:void(0);' onclick='javascript:searchBtn3(\"" + data + "\", \"" + '问题描述' + "\")' ><i style='font-weight: bold' class='layui-icon layui-icon-search'></i></a> ";
                                } else {
                                    return data;
                                }
                            } else {
                                return "";
                            }
                        }

                    },
                    {"width": "95", "data": "questionStatus", "defaultContent": "",},
                    {
                        "width": "120",
                        "data": "remark", "defaultContent": "",
                        render: function (data, type, row, meta) {
                            if (data) {
                                if (data.length > 35) {
                                    return data.substr(0, 35) + " <a style='color: #1E9FFF ;font-size: 8px' href='javascript:void(0);' onclick='javascript:searchBtn3(\"" + data + "\", \"" + '整改落实详情' + "\")' ><i style='font-weight: bold' class='layui-icon layui-icon-search'></i></a> ";
                                } else {
                                    return data;
                                }
                            } else {
                                return "";
                            }
                        }
                    },
                    {
                        "width": "95",
                        "data": "endPatrolTime", "defaultContent": "",
                        render: function (data, type, row, meta) {

                            return dateFormat(data, "yyyy-MM-dd");


                        }
                    }
                ],
                "order": [[0, "asc"]]
            });
        return example
    }

    function searchBtn3(id, title) {
        layer.open({
            type: 1
            , title: '<div class="layui-icon" style="font-weight: bold; text-align: center">' + title + '</div>'
            , area: ["600px", ""]
            , content: '<div style="padding: 20px;font-size:18px;line-height:30px;">' + id + '</div>'
            , btnAlign: 'c' //按钮居中
            , shade: 0.3 //不显示遮罩
            , shadeClose: false
            , scrollbar: false
            , yes: function () {
                layer.closeAll();
            }
        });
    }

    //下面为点击首项选中子项;子项全选,首项选中
    $('#checkAll').on('click', function () {
        if (this.checked) {
            $(this).attr('checked', 'checked')
            $("input[name='childclick']").each(function () {
                this.checked = true;
            });
        } else {
            $(this).removeAttr('checked')
            $("input[name='childclick']").each(function () {
                this.checked = false;
            });
        }
    });

    function childclick() {

        if ($(this).is(":checked") == false) {
            $("#checkAll").prop("checked", false);
        }
        if ($("input[name='childclick']:checked").length == $("input[name='childclick']").length) {
            $("#checkAll").prop("checked", true);
        }
    }

    function excel() {
        var type = 'null';
        var year = 'null';
        var branch = 'null';

        if ($("#questionType").val() != null && $("#questionType").val() != "") {
            type = encodeURI(JSON.stringify($("#questionType").val()));
        }
        if ($("#startPatrolTime").val() != null && $("#startPatrolTime").val() != "") {
            year = encodeURI(JSON.stringify($("#startPatrolTime").val()));
        }
        if ($("#branch").val() != null && $("#branch").val() != "") {
            branch = encodeURI(JSON.stringify($("#branch").val()));
        }

        var table2 = layui.table;

        var ids = [];
        $.each($('input[name=\'childclick\']:checkbox'), function () {
            if (this.checked) {
                ids.push($(this).val())
            }
        });
        var form = layui.form;
        if (ids.length > 0) {
            // 选择导出
            ids = JSON.stringify(ids);
            location.href = '/mOverseeQuestions/excelDetailByIds?ids=' + encodeURI(ids);
        } else {
            // 导出全部
            location.href = '/mOverseeQuestions/excelDetail?type=' + type + '&year=' + year + '&branch=' + branch + '&userId=' + userId;
        }
    }

    $("#searchBt").click(function () {
        init().ajax.reload();
    });

    function setFormValue() {
        if (parent.frames['iframe102']) {
            var sendData = parent.frames['iframe102'].sendDetailData();
            if (sendData != null && typeof sendData.branch != 'undefined') {
                layui.use('form', function () {
                    var form = layui.form;
                    //高版本建议把括号去掉，有的低版本，需要加()
                    $('#branch').val(sendData.branchId);
                    $('#startPatrolTime').val(sendData.startPatrolTime);
                    $('#questionType').val(sendData.questionType);
                    form.render()
                });
            }
            init().ajax.reload();
        }
    }


    function dateFormat(dateString, format) {
        if (!dateString) return "";
        var time = new Date(dateString.replace(/-/g, '/').replace(/T|Z/g, ' ').trim());
        var o = {
            "M+": time.getMonth() + 1, //月份
            "d+": time.getDate(), //日
            "h+": time.getHours(), //小时
            "m+": time.getMinutes(), //分
            "s+": time.getSeconds(), //秒
            "q+": Math.floor((time.getMonth() + 3) / 3), //季度
            "S": time.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (time.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return format;
    }


</script>

</body>
</html>

